package com.h3c.tj_nsh.UI.Fragment;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.h3c.tj_nsh.R;
import com.h3c.tj_nsh.UI.Adapter.ITSMAdapter;
import com.h3c.tj_nsh.UI.MVP.Engineer.ITSM_Present;
import com.h3c.tj_nsh.UI.MVP.Engineer.ITSM_View_En;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 工程师的ITSM
 */

public class ITSMEngineerFra extends BaseFragment implements ITSM_View_En {


    @Bind(R.id.rv_icons)
    RecyclerView mRvIcons;
    private ITSMAdapter mAdapter;
    private String[] mLabers;
    private ITSM_Present mItsmPresent;

    @Override
    protected int getLayoutResId() {
        return R.layout.fra_engineer_itsm;
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // TODO: inflate a fragment view
        View rootView = super.onCreateView(inflater, container, savedInstanceState);
        ButterKnife.bind(this, rootView);
        mItsmPresent = new ITSM_Present(ITSMEngineerFra.this);
        final FragmentActivity activity = getActivity();
        mLabers = container.getResources().getStringArray(R.array.icon_names);
        mRvIcons.setLayoutManager(new GridLayoutManager(getContext(), 4));
        mRvIcons.setAdapter(mAdapter == null ? mAdapter = new ITSMAdapter(mLabers) : mAdapter);
        mAdapter.setOnItemClickListener(new ITSMAdapter.OnRecyclerViewItemClickListener() {
            @Override
            public void onItemClick(View view, int postion) {

                String laber = mLabers[postion];
                mItsmPresent.openItemActivity(activity, laber);

            }
        });
        return rootView;
    }

    @Override
    public void onResume() {
        super.onResume();
        mItsmPresent.getProcessDefinitionList();
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }


}
